<template>
  <div class="loginBox">
    <van-form>
        <van-cell-group inset>
          <van-field
            v-model="mobile"
            name="手机号"
            label="手机号"
            placeholder="手机号"
            :rules="[{ required: true, message: '请填写手机号' }]"
          />
        </van-cell-group>
        <div style="margin: 16px;">
          <van-button round block type="primary" @click="login">登录</van-button>
        </div>
      </van-form>
  </div>
</template>

<script setup>
import {ref} from "vue"
import{useRouter} from "vue-router"
import { useUserStore } from '@/stores/modules/user'
import {getMemberInfo} from '@/api/qy-wechat-api'
import {toast} from '@/utils/vant'

const router = useRouter()
const userStore = useUserStore()

const mobile = ref('')

const login = async ()=>{
    if(!mobile.value){
        return toast('请输入手机号')
    }
    const res = await getMemberInfo({mobile:mobile.value})
    if(res.code == 200 && res.data){
        userStore.setUserInfo(res.data)
        router.push({name:'Index'})
    }else{
        toast(res.message || '登录出错')
    }
}
</script>

<style lang="scss">
.loginBox{
  padding: 30px 0;
}
</style>